//-----------------------------------------------
//  Copyright (c) 2007 Microsoft
//  Exchange Web Services Gadget
// ----------------------------------------------

/*
//function: displayItems
//This function is the common interface that is 
//called by all methods to display the items.
*/ 
function displayItems(myItems, myItemIds)
{
    var myTopicNamesClass = "TopicNames";
    var myTopicNamesBoldClass = "TopicNamesBold";
    var mySubTitleClass = "SubTitlesNormal";
    var mySubTitleBoldClass = "SubTitlesBold";
    var mySubjectClass = "SubjectNormal";
    var mySubjectBoldClass = "SubjectBold";
    var myDuringClass = "CalendarTopicNamesRed";
    var myDockedRowClass = "dockedTile";
    var myUndockedRowClass = "myUnDockedInbox";

    var skin = widget.preferenceForKey("YourDockedTheme");
    
    // These are static cut off values for the display items in the rows. They can change to increase the length of what is displayed
    var cutOff = 23;
    var cutOffSmall = 37;
    var cutOffSmallBold = 33;
    
    var cutOffDockedDuring = 16;
    var cutOffDocked = 15;
    var cutOffDockedSmallBold = 19;
    var cutOffDockedSmall = 24;
    var finalString = "";
    
    if (skin == "InboxOnly")
    {
        finalString = processMailItems(myItems,myItemIds, myTopicNamesClass, myTopicNamesBoldClass, mySubTitleClass, mySubTitleBoldClass, mySubjectClass, mySubjectBoldClass, myDockedRowClass, myUndockedRowClass, cutOff, cutOffDocked,cutOffDockedSmall, cutOffDockedSmallBold, cutOffSmall, cutOffSmallBold, cutOffDockedDuring);
    }
    else if (skin == "CalendarOnly")
    {
        finalString = processCalendarItems(myItems,myItemIds, myTopicNamesClass, myTopicNamesBoldClass, mySubTitleClass, mySubTitleBoldClass, mySubjectClass, mySubjectBoldClass, myDuringClass, myDockedRowClass, myUndockedRowClass, cutOff, cutOffDocked,cutOffDockedSmall,cutOffDockedSmallBold, cutOffSmall, cutOffSmallBold, cutOffDockedDuring);
    }
    else if (skin == "TasksOnly") 
    {
        finalString = processTaskItems(myItems,myItemIds, myTopicNamesClass, myTopicNamesBoldClass, mySubTitleClass, mySubTitleBoldClass, mySubjectClass, mySubjectBoldClass, myDockedRowClass, myUndockedRowClass, cutOff, cutOffDocked,cutOffDockedSmall,cutOffDockedSmallBold, cutOffSmall, cutOffSmallBold, cutOffDockedDuring);
    }
    
    return finalString;
}

//
// function: processMailItems
// This function handles all the mail specific functions required to display the mail
//
function processMailItems(myItems, myItemIds, myTopicNamesClass, myTopicNamesBoldClass, mySubTitleClass, mySubTitleBoldClass, mySubjectClass, mySubjectBoldClass, myDockedRowClass, myUndockedRowClass, cutOff, cutOffDocked,cutOffDockedSmall, cutOffDockedSmallBold, cutOffSmall, cutOffSmallBold, cutOffDockedDuring)
{
    var i, j, k;
    var finalString = "";
    var numberofItemsToShow = 0;

    k = 0;
    j = 0;

    var topItemNumber = 0;
    var totalNumberofItems = totalNumberOfMessages;        
	
	
    // Set the size of the display based on whether or not the gadget is docked.
    if (isDocked())
    {
        finalString = "<table width=120 cellspacing=0 cellpadding=0 border=0>";
    }
    else
    {
        finalString = "<table width=280 cellspacing=0 cellpadding=0 border=0 style=position:absolute;top:4px;left:0px;>";
    }


    // This sets how many items should display
    topItemNumber = 5;   
    

    // This counts the number of messages and compares to how many should display
    if (topItemNumber > myItems.length)
    {
        topItemNumber = myItems.length;
    }
    // Iterate through all the messages that are to be displayed
    for (i = 0 ; i < myItems.length; i++) 
    {
        // Determine if the message has been read
        var tempNode = myItems[i].selectSingleNode("t:IsRead");
        var isReadText = "";
        if (tempNode != null)
        {
            isReadText = tempNode.text;
        }
        // Determine if the message has attachments
        tempNode = myItems[i].selectSingleNode("t:HasAttachments");
        var hasAttachmentsText = "";
        if (tempNode != null)
        {
            hasAttachmentsText = tempNode.text;
        }

        // Determine the Importance of the message; show an indicator if the importance is high
        tempNode = myItems[i].selectSingleNode("t:Importance");
        var importanceText = "";
        if (tempNode != null)
        {
            importanceText = tempNode.text;
        }

        // Get the sender's name
        var nameText = "";
        tempNode = myItems[i].selectSingleNode("t:From/t:Mailbox/t:Name");
        if (tempNode != null)
        {
            nameText = tempNode.text;
        }

        // Display when the message was received 
        tempNode = myItems[i].selectSingleNode("t:DateTimeReceived");
        var dateTimeText = "";
        if (tempNode != null)
        {
            dateTimeText = tempNode.text;
        }

        // format the date into the current time zone
        var tempDate = "";
        if(dateTimeText != "")
        {
            tempDate = fullDate(dateTimeText)
        }

        // Display the subject of the message
        tempNode = myItems[i].selectSingleNode("t:Subject");
        var subjectText = "";
        if (tempNode != null)
        {
            subjectText = tempNode.text;
        }

        // Get the specific Id and ChangeKey of the message
        var tempId = myItemIds[i].getAttribute("Id");
        var tempChangeKey = myItemIds[i].getAttribute("ChangeKey");


        finalString += "<span onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','mail');><tr class='" + myUndockedRowClass + "'>";

     
        // This section determines how to display the name of the person who sent the message
        if (isDocked()) //docked
        {
            if (hasAttachmentsText == "true" && isReadText == "false")
            {
                finalString += "<td><div style='text-overflow:ellipsis;width:100;overflow:ellipsis'><span class='" + myTopicNamesBoldClass + "' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','mail');>" + nameText + "</span><br>";
            }
            else if (hasAttachmentsText == "false" && isReadText == "false")
            {
                finalString += "<td><div style='text-overflow:ellipsis;width:100;overflow:ellipsis'><span  class='" + myTopicNamesBoldClass + "'  onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','mail');>" + nameText + "</span><br>";
            }
            else
            {
                finalString += "<td><div style='text-overflow:ellipsis;width:100;overflow:ellipsis'><span  class='" + myTopicNamesClass + "' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','mail');>" + nameText + "</span><br>";
            }
        }   
        else
        {
            if (hasAttachmentsText == "true" && importanceText == "High" && isReadText == "false")
            {
                finalString += "<td><div style='text-overflow:ellipsis;width:175;overflow:ellipsis'><span  class='" + myTopicNamesBoldClass + "' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','mail');><img src='../images/paperclip.png' height='8' width='7'>&nbsp;<font color='#FF0000'><b>!</b></font>&nbsp;" + nameText + "</span><br>";
            }
            else if (hasAttachmentsText == "true" && importanceText == "High" && isReadText == "true")
            {
                finalString += "<td><div style='text-overflow:ellipsis;width:175;overflow:ellipsis'><span class='" + myTopicNamesClass + "Undocked' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','mail');><img src='../images/paperclip.png' height='8' width='7'>&nbsp;<font color='#FF0000'><b>!</b></font>&nbsp;" + nameText + "</span><br>";
            }
            else if (hasAttachmentsText == "true" && importanceText != "High" && isReadText == "false")
            {
                finalString += "<td><div style='text-overflow:ellipsis;width:175;overflow:ellipsis'><span class='" + myTopicNamesBoldClass + "Undocked' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','mail');><img src='../images/paperclip.png' height='8' width='7'>&nbsp;" + nameText + "</span><br>";
            }
            else if (hasAttachmentsText == "true" && importanceText != "High" && isReadText == "true")
            {
                finalString += "<td><div style='text-overflow:ellipsis;width:175;overflow:ellipsis'><span class='" + myTopicNamesClass + "Undocked' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','mail');><img src='../images/paperclip.png' height='8' width='7'>&nbsp;" + nameText + "</span><br>";
            }
            else if (hasAttachmentsText == "false" && importanceText == "High" && isReadText == "false")
            {
                finalString += "<td><div style='text-overflow:ellipsis;width:175;overflow:ellipsis'><span  class='" + myTopicNamesBoldClass + "Undocked' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','mail');><font color='#FF0000'><b>!</b></font>&nbsp;" + nameText + "</span><br>";
            }
            else if (hasAttachmentsText == "false" && importanceText == "High" && isReadText == "true")
            {
                finalString += "<td><div style='text-overflow:ellipsis;width:175;overflow:ellipsis'><span  class='" + myTopicNamesClass + "Undocked' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','mail');><font color='#FF0000'><b>!</b> </font>&nbsp;" + nameText + "</span><br>";
            }
            else if (hasAttachmentsText == "false" && importanceText != "High" && isReadText == "false")
            {
                finalString += "<td><div style='text-overflow:ellipsis;width:175;overflow:ellipsis'><span  class='" + myTopicNamesBoldClass + "Undocked' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','mail');>" + nameText + "</span><br>";
            }
            else
            {
                finalString += "<td><div style='text-overflow:ellipsis;width:175;overflow:ellipsis'><span  class='" + myTopicNamesClass + "Undocked' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','mail');>" + nameText + "</span><br>";
            }
        }

        // This section adds the date            
        if (isReadText == "false")
        {
            finalString += "<span class='" + mySubTitleBoldClass + "'  onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','mail');>" + tempDate + "</span><br>";
        }
        else
        {
            finalString += "<span class='" + mySubTitleClass + "' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','mail');>" + tempDate + "</span><br>";
        }
		
        // This adds a separating orange line

        if (isDocked())
        {
            finalString += "<span class='OrangeLineDocked'><img src='../images/OrangeLineDocked.png'/></span><br>";
        }
        else
        {
            finalString += "<span class='OrangeLineUnDocked'><img src='../images/OrangeLineUnDocked.png'/></span><br>";
        }


        // This adds the subject line to the row            
        if (isDocked())
        {
           if (isReadText == "false")
           {
		        finalString += "<div style='text-overflow:ellipsis;width:160;overflow:ellipsis'><span class='" + mySubjectBoldClass + "Undocked' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','mail');>" + subjectText + "</span></div></td></tr></span>";
		   }
		   else
		   {
		        finalString += "<div style='text-overflow:ellipsis;width:160;overflow:ellipsis'><span class='" + mySubjectClass + "Undocked' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','mail');>" + subjectText + "</span></div></td></tr></span>";
		   }
        }
        else
        {
           if (isReadText == "false")
           {
                finalString += "<div style='text-overflow:ellipsis;width:100;overflow:ellipsis'><span class='" + mySubjectBoldClass + "' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','mail');>" + subjectText + "</span></div></td></tr></span>";
           }
           else
           {
                finalString += "<div style='text-overflow:ellipsis;width:100;overflow:ellipsis'><span class='" + mySubjectClass + "' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','mail');>" + subjectText + "</span></div></td></tr></span>";
           }
        }
    }
        
    
    // Determine how to display the next and previous text at the bottom	    
    if (topItemNumber > 0)
    {  
        var myNextPreviousText = "";
 	    myNextPreviousText = getNextPreviousText(topItemNumber, totalNumberofItems,currentPage, "getMessages");
        finalString += myNextPreviousText;
    }
    
    finalString += "</table>";

    // Display a message if no messages are present
    if(topItemNumber == 0)
    {
        if(isDocked())
        {
            finalString = "<table><tr><td><span class='lblNoText'> There are no mail items at this time.</span></td></tr></table>";
            txtInbox.innerText = "Inbox";
        }
        else
        {
            finalString = "<table><tr><td><span class='lblNoTextUndocked'> There are no mail items at this time.</span></td></tr></table>";
            txtInbox.innerText = "Inbox";
        }
    }
    
    return finalString;
}

/*
// function: processCalendarItems
// This function handles all the calendar specific functions required to display the calendar items
*/
function processCalendarItems(myItems,myItemIds, myTopicNamesClass, myTopicNamesBoldClass, mySubTitleClass, mySubTitleBoldClass, mySubjectClass, mySubjectBoldClass, myDuringClass, myDockedRowClass, myUndockedRowClass, cutOff, cutOffDocked, cutOffDockedSmall, cutOffDockedSmallBold, cutOffSmall, cutOffSmallBold, cutOffDockedDuring)
{
    var i, j, k;
    k = 0;
    var finalString = "";
    var topCalendarNumber = 0;

    totalNumberOfCalendarItems = myItems.length;

    topCalendarNumber = 5;   
    

    if (topCalendarNumber > myItems.length)
    {
        topCalendarNumber = myItems.length;
    }
        
    var myDate = new Date();

    // Create a table to display the calendar items dependent on whether the gadget is docked or not

    if (!isDocked())
    {
        finalString = "<table width=300 cellspacing=0 cellpadding=0  style=position:absolute;top:4px;left:0px;>";
    }
    else
    {
        finalString = "<table width=120 cellspacing=0 cellpadding=0>";
    }
                
    // Get the end point of the calendar items that will be shown
    var myHighEnd = topCalendarNumber + currentCalendarPage;

    if (myHighEnd > totalNumberOfCalendarItems)
    {
        myHighEnd = totalNumberOfCalendarItems;
    }
    
    // Iterate through all the items
    for (i = currentCalendarPage; i < myHighEnd; i++) 
    {
        // This variable is used to determine if the calendar item is happening right now
        var isDuring = false;
     
        // Get the start date
        var tempNode = myItems[i].selectSingleNode("t:Start");
        var  startTimeText = "";
        if (tempNode != null)
        {
            startTimeText = tempNode.text;
        }
        
        // Get the end date of the item
        tempNode = myItems[i].selectSingleNode("t:End");
        var endTimeText = "";
        if (tempNode != null)
        {
            endTimeText = tempNode.text;
        }

        // Format the start time and end teim        
        var myNewStart = transformDate(startTimeText);
        var myNewEnd = transformDate(endTimeText);
    
        // Get the Calendar Item Id and ChangeKey
        var tempId = myItemIds[i].getAttribute("Id");
        var tempChangeKey = myItemIds[i].getAttribute("ChangeKey");

        // Get the subject of the calendar item
        tempNode = myItems[i].selectSingleNode("t:Subject");
        var subjectText = "";
        if (tempNode != null)
        {
            subjectText = tempNode.text;
        }
        
        // Get the location of the calendar item
        tempNode = myItems[i].selectSingleNode("t:Location");
        var locationText = "";
        if (tempNode != null)
        {
            locationText = tempNode.text;
        }
        
        // Determine if the event is happening now
        if (Date.parse(myDate) >= Date.parse(myNewStart) && Date.parse(myDate) <= Date.parse(myNewEnd))
        {
            isDuring = true;
        }
        
        // Determine how to display the row
        if (isDocked())
        {
            finalString += "<span onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','calendar');><tr class='" + myDockedRowClass + "'>";
        }
        else
        {
            finalString += "<span onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','calendar');><tr class='" + myUndockedRowClass + "'>";
        }


            
        // If the event is happening right now, change the visual feedback
        if (isDuring)
        {
            if (!isDocked())
            {
                finalString += "<td><div style='text-overflow:ellipsis;width:160;overflow:ellipsis'><span class='" + myDuringClass + "Undocked'  onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','calendar');>" + subjectText + "</span><BR>";
            }
            else
            {
                finalString += "<td><div style='text-overflow:ellipsis;width:100;overflow:ellipsis'><span  class='" + myDuringClass + "' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','calendar');>" + subjectText + "</span><BR>";
            }
        }
        // If the event is not happening right now, display the regular font
        else
        {
            if (!isDocked())
            {
                finalString += "<td><div style='text-overflow:ellipsis;width:160;overflow:ellipsis'><span  class='" + myTopicNamesClass + "Undocked' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','calendar');>" + subjectText + "</span><BR>";
            }
            else
            {
                finalString += "<td><div style='text-overflow:ellipsis;width:100;overflow:ellipsis'><span  class='" + myTopicNamesClass + "'  onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','calendar');>" + subjectText + "</span><BR>";
            }
        }
        
        // Get the location of the calendar item
        if (!isDocked())
        {
            finalString += "<div style='text-overflow:ellipsis;width:160;overflow:ellipsis'><span class='" + mySubTitleClass + "Undocked' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','calendar');>" + locationText + "</span><BR>";
        }
        else
        {
            finalString += "<div style='text-overflow:ellipsis;width:100;overflow:ellipsis'><span  class='" + mySubTitleClass + "'  onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','calendar');>" + locationText + "</span><BR>";
        }
    
        // Add an orange line separator    
        if (isDocked())
        {
            finalString += "<span class='OrangeLineDocked'><img src='../images/OrangeLineDocked.png'/></span><br>";
        }
        else
        {
            finalString += "<span class='OrangeLineUnDocked'><img src='../images/OrangeLineUnDocked.png'/></span><br>";
        }
        
        // Display the starting and ending time of the event				
	    var startDate = transferDate(startTimeText);
	    var endDate = transferDate(endTimeText);
	    
	    finalString += "<span  class='" + mySubjectClass + "' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','calendar');>" + startDate + "-" + endDate +  "</span></div></td></tr></span>";
    }
	
	// Determine how to display the next previous text at the bottom	
    if (myHighEnd > 0)
    {
        var myNextPreviousText = "";
        myNextPreviousText = getNextPreviousText(topCalendarNumber, totalNumberOfCalendarItems, currentCalendarPage, "getCalendarItems");
        finalString += myNextPreviousText;
    }

    finalString += "</table>"

    // Display a message if no calendar items are found
    if (myHighEnd == 0)
    {
        if (isDocked())
        {
            finalString = "<table><tr><td><span class='lblNoText'>There are no calendar items at this time.</span></td></tr></table>";
        }
        else
        {
            finalString = "<table><tr><td><span class='lblNoTextUndocked'>There are no calendar items at this time.</span></td></tr></table>";
        }
    }
    
    return finalString;
}

//
// function: processTaskItems
// This function handles all task specific functions required to display the task items
//
function processTaskItems(myItems,myItemIds, myTopicNamesClass, myTopicNamesBoldClass, mySubTitleClass, mySubTitleBoldClass, mySubjectClass, mySubjectBoldClass, myDockedRowClass, myUndockedRowClass, cutOff, cutOffDocked, cutOffDockedSmall, cutOffDockedSmallBold, cutOffSmall, cutOffSmallBold, cutOffDockedDuring)
{
    var finalString = "";
    var topTaskNumber = 0;
    var i, j, k;
    k = 0;

    // Determine how many tasks should show in the gadget  
    var numberofTaskItemsToShow = 5;

    // Determine if then total number of tasks is less than the number returned
    if (numberofTaskItemsToShow < myItems.length)
    {
        topTaskNumber = numberofTaskItemsToShow;
    }        
    else
    {
        topTaskNumber = myItems.length;
    }
     
    if (myItems.length == 0)
    {
        //lblTasks.innerText = "";
    }

    var finalString = "";
           
    // Create a table based on whether the gadget is docked or not
    if (isDocked())
    {
        finalString = "<table cellspacing=0 cellpadding=0 border=0 width=300  style=position:absolute;top:4px;left:0px;>";
    }
    else
    {
        finalString = "<table width=120 cellspacing=0 cellpadding=0>";
    }
     
    // Iterate through the tasks
    for (i = 0 ; i < topTaskNumber; i++) 
    {
        // Get the task Id and ChangeKey
        var tempId = myItemIds[i].getAttribute("Id");
        var tempChangeKey = myItemIds[i].getAttribute("ChangeKey");

        // Get the status of the task
        var statusText = "";
        var tempNode = myItems[i].selectSingleNode("t:Status");
        if (tempNode != null)
        {
            statusText = tempNode.text;
        }

        // Get the subject of the task
        tempNode = myItems[i].selectSingleNode("t:Subject");
        var subjectText = "";
        if (tempNode != null)
        {
            subjectText = tempNode.text;
        }

        // Get the due date of the task
        tempNode = myItems[i].selectSingleNode("t:DueDate");
        var dueDateText = "";
        if (tempNode != null)
        {
            dueDateText = tempNode.text;
        }

        var className = myTopicNamesClass;

        // Determine how to display the row    
        if (isDocked())
        {
            finalString += "<span onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','task');><tr  class='" + myDockedRowClass + "'>";
        }
        else
        {
            finalString += "<span onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','task');><tr class='" + myUndockedRowClass + "'>";
        }
            
        // Display a strike through the subject depending if the task is completed
        if (!isDocked())
        {
            if (statusText == "Completed")
            {
                finalString += "<td><div style='text-overflow:ellipsis;width:160;overflow:ellipsis'><span class='" + myTopicNamesClass + "Undocked' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','task');><strike>" + subjectText + "</strike></span><br>";
            }
            else
            {
                finalString += "<td><div style='text-overflow:ellipsis;width:160;overflow:ellipsis'><span class='" + myTopicNamesClass + "Undocked' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','task');>" + subjectText + "</span><br>";
            }
        }
        else
        {
            if (statusText == "Completed")
            {
                finalString += "<td><div style='text-overflow:ellipsis;width:100;overflow:ellipsis'><span  class='" + myTopicNamesClass + "' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','task');><strike>" + subjectText + "</strike></span><br>";
            }
            else
            {
                finalString += "<td><div style='text-overflow:ellipsis;width:100;overflow:ellipsis'><span  class='" + myTopicNamesClass + "' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','task');>" + subjectText + "</span><br>";
            }
        }
        
        // Display the current status of the task    
        finalString += "<span  class='" + mySubTitleClass + "' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','task');>" + statusText + "</span><br>";
           
        // Add an orange line separator     
        if (isDocked())
        {
            finalString += "<span class='OrangeLineDocked'><img src='../images/OrangeLineDocked.png'/></span><br>";
        }
        else
        {
            finalString += "<span class='OrangeLineUnDocked'><img src='../images/OrangeLineUnDocked.png'/></span><br>";
        }
    
        // Get the due date of the task
        if (dueDateText != "")
        {
            finalString += "<span  class='" + mySubjectClass + "' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','task');>" + transferDate(dueDateText) + "</span></div></td></tr></span>";
        }
        else
        {
            finalString += "<span  class='" + mySubjectClass + "' onclick=openFlyout('" + tempId + "','" + tempChangeKey + "','task');>None</span></div></td></tr></span>";
        }
    }
    
    // Display the next previous buttons at the bottom    	        
    if (topTaskNumber > 0)
    {
        var myNextPreviousText = "";
        myNextPreviousText = getNextPreviousText(topTaskNumber, totalNumberOfTaskItems, currentTaskPage, "getTaskItems");
        finalString += myNextPreviousText;
    }
    
    finalString += "</table>";
    
    // Display a message if no tasks are available
    if (topTaskNumber == 0)
    {
        if (isDocked())
        {
            finalString = "<table width=100><tr><td><span class='lblNoText'>There are no task items at this time.</span></td></tr></table>";
        }
        else
        {
            finalString = "<table width=100><tr><td><span class='lblNoTextUndocked'>There are no task items at this time.</span></td></tr></table>";
        }
    }
    
    return finalString;
}

//
// function: getNextPreviousText
// This function handles all the next/previous functions for each module
//
function getNextPreviousText(topItemNumber, totalNumberofItems, myCurrentPage, functionName)
{
    var finalString = "";

    if (topItemNumber > 0)
    {
        var firstNumber = myCurrentPage + 1;
        var secondNumber = myCurrentPage + topItemNumber;
        if (secondNumber > totalNumberofItems && totalNumberofItems > 0)
        {
            secondNumber = totalNumberofItems;
        }

        var numbersText = "";
        var numberClass = "";
        numberClass = "lblNextPreviousInbox";
        
        if (isDocked())
        {
            // Change the display of the current numbers depending on the size of the number
            if (firstNumber < 1000 && secondNumber < 1000)   
            {
                numbersText = "(" + firstNumber + "-" + secondNumber + ")";
            }
            
            if (firstNumber > 100 && secondNumber > 100)
            {
                numberClass = "lblNextPrevious100Inbox";
            }
            else if (firstNumber > 10 && secondNumber > 10)
            {
                numberClass = "lblNextPrevious10Inbox";
            }
                    
            var myPreviousClass = "";
            var myNextClass = "";
             
            myPreviousClass = "lblPreviousTextInbox";
            myNextClass = "lblNextTextInbox";

            // If you are at the beginning
            if (firstNumber == 1)
            {
                myPreviousClass = "lblPreviousTextInboxGray";
            }
            
            // If you have reached the end
            if (totalNumberofItems <= secondNumber)
            {
                myNextClass = "lblNextTextInboxGray";
            }

            finalString +="<tr><td><a href='javascript:" + functionName + "(2);'><span class='" + myPreviousClass + "'>Previous</span></a><span class='" + numberClass + "'>" + numbersText + "</span><a href='javascript:" + functionName + "(3);'><span class='" + myNextClass + "'>Next</span></a></td></tr>";
        }
        else
        {
            if (firstNumber == 1)
            {
                finalString +="<tr><td><span class='CounterBox'><span class='CounterBoxText'>" + firstNumber + "-" + secondNumber + "</span></span><span class='myNextPrevious'><span class='PreviousButton'><img src='../images/PreviousArrow.png' border=0></span><span class='lblNextPreviousUndocked'>Previous</span>&nbsp;<a href='javascript:" + functionName + "(3);'><span class='lblNextPreviousUndocked'>Next</span></a><span class='NextButton'><a href='javascript:" + functionName + "(3);'><img src='../images/NextArrow.png' border=0></a></span></span></td></tr>";
            }

            if  (totalNumberofItems <= secondNumber)
            {
                finalString +="<tr><td><span class='CounterBox'><span class='CounterBoxText'>" + firstNumber + "-" + secondNumber + "</span></span><span class='myNextPrevious'><span class='PreviousButton'><a href='javascript:" + functionName + "(2);'><img src='../images/PreviousArrow.png' border=0></a></span><a href='javascript:" + functionName + "(2);'><span class='lblNextPreviousUndocked'>Previous</span></a>&nbsp;<a href='javascript:" + functionName + "(3);'><span class='lblNextPreviousUndocked'>Next</span></a><span class='NextButton'><img src='../images/NextArrow.png' border=0></span></span></td></tr>";
            }
            else
            {
                finalString +="<tr><td><span class='CounterBox'><span class='CounterBoxText'>" + firstNumber + "-" + secondNumber + "</span></span><span class='myNextPrevious'><span class='PreviousButton'><a href='javascript:" + functionName + "(2);'><img src='../images/PreviousArrow.png' border=0></a></span><a href='javascript:" + functionName + "(2);'><span class='lblNextPreviousUndocked'>Previous</span></a>&nbsp;<a href='javascript:" + functionName + "(3);'><span class='lblNextPreviousUndocked'>Next</span></a><span class='NextButton'><a href='javascript:" + functionName + "(3);'><img src='../images/NextArrow.png' border=0></a></span></span></td></tr>";
            }
        }
    }
    return finalString;	      
}